/**
 * 获取用户数据接口
 */

//引入Q模块
let Q = require('q');

//getUserData入口函数
let index = function(getData, postData, config, _redis, db) {
	let deferred = Q.defer();
	if(postData.userId) {
		db.connectDB('common').then(function(commonDB) {
			return commonDB.select('users', {
				userId: postData.userId
			});
		}, function() {
			//连接公用common数据库失败
			deferred.reject('-0044');
		}).then(function(userData) {
			if(userData && userData[0]) {
				deferred.resolve(userData[0]);
			}
			else {
				deferred.resolve({});
			}
		}, function() {
			//mongodb查找用户列表失败
			deferred.reject('-0046');
		});
	}
	else {
		deferred.reject('-0046');
	}
	return deferred.promise;	
}

//暴露接口
module.exports = {
	index: index
};

